﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Testing_components;

namespace BuildingTomorow
{
   public class Condition
    {
       public SensorDB sensor{get; set;}
       public Operator operatorCondition{get; set;}
       public double conditionalValue { get; set; }
       public delegate bool ConditionMet();
       public ConditionMet condition;
       public bool IsConditionMet()
        {
           if(condition == null) condition = DefaultCondition;
           return condition();
        }

       private bool DefaultCondition()
       {
           switch (operatorCondition.Op)
           {
               case "<":
                   return DataAccess.GetInstance().GetSensorLastReading(sensor.ID).Value < conditionalValue;
               case ">":
                   return DataAccess.GetInstance().GetSensorLastReading(sensor.ID).Value > conditionalValue;
               case "<=":
                   return DataAccess.GetInstance().GetSensorLastReading(sensor.ID).Value <= conditionalValue;
               case ">=":
                   return DataAccess.GetInstance().GetSensorLastReading(sensor.ID).Value >= conditionalValue;
               case "==":
                   return DataAccess.GetInstance().GetSensorLastReading(sensor.ID).Value == conditionalValue;
               case "!=":
                   return DataAccess.GetInstance().GetSensorLastReading(sensor.ID).Value != conditionalValue;
           }
           DataAccess.GetInstance().Log("Error with Operator in Condition \"" + operatorCondition.Op + "\"");
           return false;
       }

    }
}
